<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title></title>

    <link rel="stylesheet" th:href="@{/res/css/amazeui.min.css}">
    <link rel="stylesheet" th:href="@{/res/css/admin.css}">

    <script th:src="@{/js/jquery-1.11.3.min.js}"></script>
    <script th:src="@{/myplugs/js/plugs.js}"></script>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" tppabs="http://res.layui.com/layui/dist/css/layui.css"
          media="all">
    <script th:src="@{/layui/layui.js}"></script>
</head>

<body>

<div class="admin-content-body">
    <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">用户管理</strong><small></small></div>
        <div style="float: right">共<span id="total"></span>条记录</div>
    </div>

    <hr>

    <div class="am-g" style="margin-top: 5px;">
        <div class="am-u-sm-12">

            <table class="layui-table">
                <thead>
                <tr>
                    <th style="width: 50px">序号</th>
                    <th style="width: 200px">用户名</th>
                    <th style="width: 80px">用户类型</th>
                    <th style="width: 200px">邮箱</th>
                    <th style="width: 200px">手机</th>
                    <th style="width: 50px">操作</th>
                </tr>
                </thead>
                <tbody id="userTable">

                </tbody>
            </table>
            <div id='page' style="text-align: center"></div>
        </div>
    </div>
</div>

<script>
    // 从url得到uid
    var result = new Object();
    result = getParameter();
    var uid = result["uid"];


    var size = 9;      // 每页的数据行
    var total = 0;     // 总数据量
    var data;          // 传入数据


    // 分页
    function cutPage() {
        layui.use(['laypage', 'layer'], function () {
            var laypage = layui.laypage,
                layer = layui.layer;
            //总页数大于页码总数
            laypage.render({
                elem: 'page'
                , count: $("#total").html()
                , first: '首页'
                , last: '尾页'
                , prev: '<em>上一页</em>'
                , next: '<em>下一页</em>'
                , limit: size
                , jump: function (obj) { //jump主要是包含要执行的函数
                    getList(obj.curr)
                }
            })
        })
    }

    // 获取总数据条数
    $(function () {
        $.get(
            "/user/getUserAllNotAdmin?uid=" + uid,
            function (data) {
                getList(1)
                $("#total").html(data.length);
                cutPage();
            }
        )
    });


    // 分页获取数据
    function getList(num) {
        $.get(
            "/user/getUserAllNotAdminByPage?uid=" + uid + "&pageSize=" + size + "&pageNum=" + num,
            function (data) {
                write(data)
            }
        )
    }

    // 渲染页面
    function write(data) {
        var str = '';
        for (var i = 0; i < data.length; i++) {
            str += '<tr>';
            str += '<td>' + (i + 1) + '</td>';
            str += '<td>' + data[i].name + '</a> </td>';
            if (data[i].accountType == "1")
                str += '<td>品牌商</td>';
            else if (data[i].accountType == "2")
                str += '<td>借卖方</td>';
            else
                str += '<td>管理员</td>';
            str += '<td>' + data[i].email + '</td>';
            str += '<td>' + data[i].phone + '</td>';
            str += '<td>';
            str += '<button type="button" class="layui-btn layui-btn-danger" onclick="delUser(\'删除用户\',' + data[i].id + ')">';
            str += '<span class="am-icon-trash-o"></span> 删除</button>';
            str += '</td>';
            str += ' </tr>';
        }

        $("#userTable").html(str);
    }

    // 添加删除弹出层
    function delUser(title, id) {
        $.jq_Panel({
            title: title,
            iframeWidth: 350,
            iframeHeight: 100,
            url: "/deleteUser?id=" + id
        });
    }

    // 解析url传值
    function getParameter() {
        var url = location.search;// 获取url?后面的内容
        var result = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                result[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
            }
        }
        return result;
    }
</script>
</body>
</html>